package com.dikeleakagedetection.myapplication.ui.database

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.dikeleakagedetection.myapplication.R

class DotAdapter(val context: Context, private val dotList: ArrayList<com.dikeleakagedetection.myapplication.logic.dao.Dot>) : RecyclerView.Adapter<DotAdapter.ViewHolder>() {
    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val tvDotMagneticX: TextView = view.findViewById(R.id.tv_dot_magnetic_x)
        val tvDotMagneticY: TextView = view.findViewById(R.id.tv_dot_magnetic_y)
        val tvDotMagneticZ: TextView = view.findViewById(R.id.tv_dot_magnetic_z)
        val tvDotAttitudeX: TextView = view.findViewById(R.id.tv_dot_attitude_x)
        val tvDotAttitudeY: TextView = view.findViewById(R.id.tv_dot_attitude_y)
        val tvDotAttitudeZ: TextView = view.findViewById(R.id.tv_dot_attitude_z)
        val tvDotLocationLng: TextView = view.findViewById(R.id.tv_dot_location_lng)
        val tvDotLocationLat: TextView = view.findViewById(R.id.tv_dot_location_lat)
        val tvDotLocationAlt: TextView = view.findViewById(R.id.tv_dot_location_alt)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_dot_act_tablet, parent, false)
        val holder = ViewHolder(view)
        return holder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val dot = dotList[position]
        holder.tvDotMagneticX.text = dot.magneticX.toString()
        holder.tvDotMagneticY.text = dot.magneticY.toString()
        holder.tvDotMagneticZ.text = dot.magneticZ.toString()
        holder.tvDotAttitudeX.text = dot.attitudeX.toString()
        holder.tvDotAttitudeY.text = dot.attitudeY.toString()
        holder.tvDotAttitudeZ.text = dot.attitudeZ.toString()
        holder.tvDotLocationLng.text = dot.locationLng
        holder.tvDotLocationLat.text = dot.locationLat
        holder.tvDotLocationAlt.text = dot.locationAlt
    }

    override fun getItemCount() = dotList.size
}